﻿using MobileBSC_Data;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MobileBSC_SQLite
{
    public class WeakSignalReader
    {
        private const string SELECT_STMT =
            "SELECT " +
                 "WeakSignalID " +
               ", Name " +
               ", Description " +
               ", Source " +
            "FROM WeakSignal ";

        public WeakSignal ReadByID(long id)
        {
            var statement = SELECT_STMT + "WHERE WeakSignalID = @id;";
            var parameters = new List<SQLiteParameter>();
            parameters.Add(new SQLiteParameter("@id", id));

            return DbTool<WeakSignal>.ReadSingle(statement, parameters, CreateWeakSignal);
        }
        public List<WeakSignal> ReadAll()
        {
            var statement = SELECT_STMT + ";";

            return DbTool<WeakSignal>.ReadMultiple(statement, null, CreateWeakSignal);
        }
        private WeakSignal CreateWeakSignal(SQLiteDataReader rd)
        {
            WeakSignal result = new WeakSignal();
            result.ID = (long)rd["WeakSignalID"];
            result.Name = (string)rd["Name"];
            if (rd.IsDBNull(rd.GetOrdinal("Description")))
                result.Description = "";
            else
                result.Description = (string)rd["Description"];
            result.Source = (string)rd["Source"];

            return result;
        }
    }
}
